package com.gitee.wsl.mathematics.matrix.mat

import com.gitee.wsl.io.dataproxy.DataProxy
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.matrix.M
import com.gitee.wsl.mathematics.matrix.MatCopyInitializer
import com.gitee.wsl.mathematics.matrix.MutableMatrixD
import com.gitee.wsl.mathematics.matrix.N
import com.gitee.wsl.mathematics.vector.vec.MutableVec
import com.gitee.wsl.mathematics.vector.vec.Vec

class MutableMat(
    rowCount: Int,
    colCount: Int,
    proxy: DataProxy<Double> = DoubleArray(rowCount * colCount).asProxy()
): Mat(rowCount, colCount, proxy), MutableMatrixD<Mat, Vec> {

    override val m by lazy{ (0 until rowCount).map { M[it] }}

    override val n by lazy {(0 until colCount).map { N[it] }}

    override fun copy(block: MatCopyInitializer<Double>): MutableMat {
        val values=DoubleArray(proxy.size)
        rowIndices.forEach { r->
            colIndices.forEach { c->
                values[r col c] = this[r,c].block(r,c)
            }
        }
        return MutableMat(rowCount,colCount,values.asProxy())
    }

    override fun createVec(indexes: List<Int>): MutableVec = MutableVec(proxy = proxy.asProxy(indexes))

}